#define  _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    int maximumBeauty(vector<int>& nums, int k) {
        sort(nums.begin(), nums.end());
        int n = nums.size();
        int l = 0, r = 0;
        while (r < n)
        {
            if (nums[r] - k > nums[l] + k) l++;
            r++;
        }
        return n - l;
    }
};